
package com.yytek.common.web.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 物模型消息
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ThingModelMessage {

    public static final String TYPE_LIFETIME = "lifetime";
    public static final String TYPE_STATE = "state";
    public static final String TYPE_PROPERTY = "property";
    public static final String TYPE_EVENT = "event";
    public static final String TYPE_SERVICE = "service";
    public static final String TYPE_CONFIG = "config";

    public static final String ID_PROPERTY_GET = "get";
    public static final String ID_PROPERTY_SET = "set";
    public static final String ID_CONFIG_GET = "get";
    public static final String ID_CONFIG_SET = "set";
    /**
     * 消息id
     */
    private String mid;
    /**
     * 设备id
     */
    private String deviceId;
    /**
     * 产品key
     */
    private String productKey;
    /**
     * 消息类型
     * lifetime:生命周期
     * state:状态
     * property:属性
     * event:事件
     * service:服务
     */
    private String type;
    /**
     * 方法识别名称
     */
    private String identifier;

    /**
     * 消息状态码
     */
    private int code;
    /**
     * 消息提示信息
     */
    private String msg;
    /**
     * 传送数据
     */
    private List<ProCommonMessage> data;

    /**
     * 消息上报时间
     */
    private Long time;

    public Map<String, Object> dataToMap() {
        Map<String, Object> mapData = new HashMap<>();
        if (data instanceof Map) {
            ((Map<?, ?>) data).forEach((key, value) -> mapData.put(key.toString(), value));
        }
        return mapData;
    }
}
